<template>
	<view class="timer">
		<view>{{ti}}</view>
		<button class="" @click="begin">开始</button>
		<button class="" @click="pause">暂停</button>
	</view>

</template>
<script>
	export default {
		data() {
			return {
				ti: '00:00:00',
				timer: '',

				hour: 0,
				minutes: 0, 
				seconds: 0,
				result: null,
			};
		},
		onLoad: function(option) {
			console.log(option.result);
			this.result = JSON.parse(option.result);
			console.log(this.result);
		},
		destroyed() {
			clearInterval(this.timer);
		},

		methods: {
			// 开始计时
			begin() {
				this.timer = setInterval(this.startTimer, 1000);
			},
			startTimer() {
				this.seconds += 1;
				if (this.seconds >= 60) {
					this.seconds = 0;
					this.minute = this.minute + 1;
				}

				if (this.minute >= 60) {
					this.minute = 0;
					this.hour = this.hour + 1;
				}
				this.ti = (this.hour < 10 ? '0' + this.hour : this.hour) + ':' + (this.minutes < 10 ? '0' + this.minutes :
					this.minutes) + ':' + (this.seconds < 10 ? '0' + this.seconds : this.seconds);
			},
			// 暂停倒计时
			pause() {
				if (this.timer) {
					clearInterval(this.timer);
					// this.timer = null
					console.log(this.timer)
				}
			},
		}
	};
</script>
<style></style>